var months = ['31', '28', '31', '30', '31', '30', '31', '31', '30', '31', '31', '31'];
// 营业时间：上午10:00 -- 下午18:00
const STARTHOUR = 10;
const ENDHOUR = 18;
var date = new Date();
function handleLeapYear(year) {
	if((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {
		months[1] = 29;
	}
	months[1] = 28;
}
export default {
	initDate(timestamp) {
		// 向后延长两个小时
		timestamp += (2 * 60 * 60 * 1000);
		date = new Date(timestamp);
		let hour = 0, minute = 0, second = 0, milliSecond = 0;
		/*
			以下两种情况从第二天的开始营业时间开始计算
			1. 仍在当天，但已经大于等于结束营业时间
			2. 在第二天，小于(等于不算，因为此时一定处于营业时间内)开始营业时间
		*/
		if(date.getHours() >= ENDHOUR) {
			hour = (23 - date.getHours()) + STARTHOUR;
			minute = (59 - date.getMinutes());
			second = (59 - date.getSeconds());
			milliSecond = (1000 - date.getMilliseconds());
		}
		if(date.getHours() < STARTHOUR) {
			hour = (STARTHOUR - 1 - date.getHours());
			minute = (59 - date.getMinutes());
			second = (59 - date.getSeconds());
			milliSecond = (1000 - date.getMilliseconds());
		}
		timestamp += (hour * 60 * 60 * 1000);
		timestamp += (minute * 60 * 1000);
		timestamp += (second * 1000);
		timestamp += milliSecond;
		date = new Date(timestamp);
	},
	getYears() {
		return [date.getFullYear(), date.getFullYear() + 1];
	},
	getMonths(year) {
		handleLeapYear(year);
		let res = [];
		let stMonth = 1;
		if(year == date.getFullYear()) {
			stMonth = date.getMonth() + 1;
		}
		for(let i = stMonth; i <= 12;i ++) {
			res.push(i);
		}
		return res;
	},
	getDays(month) {
		let res = [];
		let stDay = 1;
		if(month == date.getMonth() + 1) {
			stDay = date.getDate();
		}
		for(let i = stDay; i <= months[month - 1];i ++) {
			res.push(i);
		}
		return res;
	},
	getTimes(day) {
		let res = [];
		let stHour = STARTHOUR;
		if(day == date.getDate()) {
			stHour = date.getHours();
			if(date.getMinutes() > 30) {
				res.push(stHour.toString() + ":" + "30");
				stHour ++;
			}
		}
		for(let i = stHour; i <= ENDHOUR;i ++) {
			res.push(i.toString() + ":" + "00");
			res.push(i.toString() + ":" + "30");
		}
		return res;
	},
	// 2023年12月29日14:00 <--> 2023-12-29 14:00
	// convertDateFormat(time) {
	// 	let year = time.substring(0, 4);
	// 	let month = time.substring(5, 7);
	// 	if(month[1] == '月') {
	// 		// 5月
	// 		month = time.substring(5, 6);
	// 	}
		
	// }
}